package web;

import model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;


public class StartPage implements Servlet {
    private ServletConfig config;

    private Logger logger = LoggerFactory.getLogger(StartPage.class);

    public void init (ServletConfig config) throws ServletException {
        this.config = config;
    }

    public void destroy() {}

    public ServletConfig getServletConfig() {
        return config;
    }

    public String getServletInfo() {
        return "A Simple Servlet";
    }

    public void service (ServletRequest request, ServletResponse response) throws ServletException,
            IOException {
        logger.info("Servlet StartPage started" );

        response.setContentType( "text/html" );
        PrintWriter out = response.getWriter();
        out.println( "<html><head>" );
        out.println( "<title>A Sample Servlet!</title>" );
        out.println( "</head>" );
        out.println( "<body>" );
        out.println( "<h1>Hello, World!</h1>" );


        ExecutorService exec = Executors.newCachedThreadPool();
        exec.submit(new Manager());
        logger.info("Manager submitted.");

        out.println( "</body></html>" );
        out.close();
    }
}

